package com.ysd.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ysd.dao.impl.CompanyDaoImpl;
import com.ysd.dao.impl.ProductCategoryDaoImpl;
import com.ysd.dao.impl.ProductDaoImpl;
import com.ysd.entity.Company;
import com.ysd.entity.Product;
import com.ysd.entity.ProductCategory;

public class ProductsServlet extends HttpServlet {

	protected void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
		
		CompanyDaoImpl cDao = new CompanyDaoImpl();
		Company c = cDao.getCompany();

		request.setAttribute("c", c);
		
		
		//产品分类
		ProductCategoryDaoImpl pCDao = new ProductCategoryDaoImpl();
		/*
		 * int page = Integer.parseInt(request.getParameter("page")); int size =
		 * Integer.parseInt(request.getParameter("size"));
		 */
		List<ProductCategory> p = pCDao.getProductCategory();
		request.setAttribute("p", p);
//		System.out.println(p);
		//根据产品分类ID查询对应的产品
		int cId=Integer.parseInt(request.getParameter("productCategoryId"));
		ProductDaoImpl pDao =new ProductDaoImpl();
		List<Product> productList=pDao.getProductList(cId);
		request.setAttribute("productList", productList);
		request.setAttribute("cId", cId);
		System.out.println(productList);
		
		ProductDaoImpl pDa = new ProductDaoImpl();
		List<Product> suiJi = pDa .getProductList3();
		request.setAttribute("suiJi", suiJi);
		
		request.getRequestDispatcher("productlist.jsp").forward(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doGet(request, response);
	}

}
